package com.manage.web.controller.function;


import com.manage.function.domain.vo.ErParem;
import com.manage.function.sqltoer.sqlback.model.TableInfo;
import com.manage.function.sqltoer.sqlback.service.SqlParserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
/**
 * @author jinghj
 * @date 2025-03-04
 * 提供接口给前端访问
 */
@Api(value ="/function/parse",  tags = "ER图管理接口")
@RestController
@RequestMapping("/function/parse")
public class ErDiagramController {

    @Autowired
    private  SqlParserService sqlParserService;

    @PostMapping("/tableInfo")
    @ApiOperation(value = "ER图管理接口" , notes = "ER图管理接口" , httpMethod = "POST")
    public ResponseEntity<List<TableInfo>> parseSql(@RequestBody ErParem erParem) {
        String sql = erParem.getSql();
        if (sql == null || sql.trim().isEmpty()) {
            return ResponseEntity.badRequest().build();
        }
        List<TableInfo> tables = sqlParserService.parseSql(sql);
        return ResponseEntity.ok(tables);
    }
} 